package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.annotation.NotNull;
import cn.yuhh.core.domain.DeclareInfo;
import cn.yuhh.core.type.DeclareStatus;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-26-19:03
 * @descreption 申报详情
 **/
@Component("declareDetail1.0")
@NotNull(name = "id")
public class DeclareDetailService extends AbstractApiService {

    @Value("${image.upload.path}")
    private String path;
    @Value("${image.domain.url}")
    private String url;


    @Override
    public Map service(Map request) {
        DeclareInfo declareInfo = mongoId(request).findOne(DeclareInfo.class);

        return ApiResponse.success(declareInfo, new IDataToMap<DeclareInfo>() {
            @Override
            public void dataToMap(Map map, DeclareInfo source) {
                map.put("selfId", selfId(request));
                source.detail(map);
                map.put("imageDomain", url);
                if(declareInfo.getDeclareStatus().equals(DeclareStatus.accepted)){
                    map.put("needReason", "Y");
                }
            }
        });
    }
}
